const cloud = require('wx-server-sdk');
const axios = require('axios'); // 需安装
cloud.init({ env: process.env.ENV_ID }); // 从环境变量读取环境ID

exports.main = async (event) => {
  const { apiName, params } = event; // 接收小程序传入参数
  const AMAP_KEY = '7308a703ca89045494912add72f1399b'; // 建议存环境变量（见步骤4）
  const url = `https://restapi.amap.com/v3/${apiName}?key=${AMAP_KEY}&${new URLSearchParams(params).toString()}`;
  
  try {
    const res = await axios.get(url);
    return res.data; // 返回高德API原始数据
  } catch (err) {
    return { code: 500, msg: '高德接口调用失败' };
  }
};